package hos.ui.drawable;

import android.graphics.drawable.Drawable;
import android.view.View;

import androidx.annotation.ColorInt;

/**
 * <p>Title: BackgroundDrawable </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2024-06-26 14:05
 */
public interface BackgroundDrawable<V extends View> {

    default BackgroundDrawable<V> setDrawable(Drawable ordinary, Drawable state) {
        if (this instanceof View) {
            ((View) this).setBackground(DrawableUtils.getDrawable(ordinary, state));
        }
        return this;
    }

    default BackgroundDrawable<V> setBackgroundStroke(@ColorInt int color, @ColorInt int strokeColor) {
        return setBackgroundStroke(color, 2, strokeColor, 12f);
    }

    default BackgroundDrawable<V> setBackgroundStroke(@ColorInt int color, int width, @ColorInt int strokeColor) {
        return setBackgroundStroke(color, width, strokeColor, 12f);
    }

    default BackgroundDrawable<V> setBackgroundStroke(@ColorInt int color, int width, @ColorInt int strokeColor,
                                                      float radius) {
        if (this instanceof View) {
            ((View) this).setBackground(DrawableUtils.getBackgroundStroke(color, width, strokeColor, radius));
        }
        return this;
    }

    default BackgroundDrawable<V> setBackgroundStroke(@ColorInt int color, int width, @ColorInt int strokeColor,
                                                      float topLeftRadius, float topRightRadius,
                                                      float bottomLeftRadius, float bottomRightRadius) {
        if (this instanceof View) {
            ((View) this).setBackground(DrawableUtils.getBackgroundStroke(color, width, strokeColor, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius));
        }
        return this;
    }


    default BackgroundDrawable<V> setBorderRadius(@ColorInt int color) {
        return setBorderRadius(2, color, 12f);
    }

    default BackgroundDrawable<V> setBorderRadius(@ColorInt int color, int width) {
        return setBorderRadius(color, width, 12f);
    }

    default BackgroundDrawable<V> setBorderRadius(@ColorInt int color, int width,
                                                  float radius) {
        if (this instanceof View) {
            ((View) this).setBackground(DrawableUtils.getBorderRadius(color, width, radius));
        }
        return this;
    }

    default BackgroundDrawable<V> setBorderRadius(@ColorInt int color, int width,
                                                  float topLeftRadius, float topRightRadius,
                                                  float bottomLeftRadius, float bottomRightRadius) {
        if (this instanceof View) {
            ((View) this).setBackground(DrawableUtils.getBorderRadius(color, width, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius));
        }
        return this;
    }

    default BackgroundDrawable<V> setBackground(@ColorInt int color) {
        return setBackground(color, 12f);
    }


    default BackgroundDrawable<V> setBackground(@ColorInt int color,
                                                float radius) {
        if (this instanceof View) {
            ((View) this).setBackground(DrawableUtils.getBackground(color, radius));
        }
        return this;
    }

    default BackgroundDrawable<V> setBackground(@ColorInt int color,
                                                float topLeftRadius, float topRightRadius,
                                                float bottomLeftRadius, float bottomRightRadius) {
        if (this instanceof View) {
            ((View) this).setBackground(DrawableUtils.getBackground(color, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius));
        }
        return this;
    }
}
